﻿<script type="text/javascript" src="javascript/ajax/prototype.js"></script>
<script type="text/javascript" src="javascript/ajax/scriptaculous.js" ></script>
<script type="text/javascript" src="javascript/ajax/effects.js" ></script>
<script type="text/javascript" src="javascript/ajax/scriptaculous.js" ></script>
<script type="text/javascript" src="javascript/colorselector/colorselector.js" ></script>

  <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/themes/base/jquery-ui.css" id="theme">
  <link rel="stylesheet" href="modules/IShopStore/pnajax/fileupload/css/jquery.fileupload-ui.css">
  <link rel="stylesheet" href="modules/IShopStore/pnajax/fileupload/css/style.css">
  
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.11/jquery-ui.min.js"></script>
  <script src="modules/IShopStore/pnajax/fileupload/js/jquery.fileupload.js"></script>
  <script src="modules/IShopStore/pnajax/fileupload/js/jquery.fileupload-ui.js"></script>
  <script src="modules/IShopStore/pnajax/fileupload/js/jquery.fileupload-uix.js"></script>
  <script src="modules/IShopStore/pnajax/fileupload/js/application.js"></script>

<link rel="stylesheet" type="text/css" href="modules/IShopStore/pnjavascript/ddtabmenu/ddtabmenufiles/ddcolortabs_blue.css" />

<script type="text/javascript">
  function validateForm(form) {
/*
    //Check image Extensions
    var valid_extensions = /(.jpg|.jpeg|.gif)$/i;
    if (valid_extensions.test(fld.value) || fld.value == ""){
       return true;
    }else{
      alert('โปรดใช้รูปนามสกุล .jpg , .jpeg หรือ .gif');
      fld.select();
      fld.focus();
      return false;
    }
*/
    //Check category
    var category = document.getElementById("form_categories_id_");
    if (category.value == 0) {
      alert("Please select Category.");
      document.getElementById('error-category').innerHTML = " Select Category.";
      category.focus();
      return false;
    }else{
      document.getElementById('error-category').innerHTML = "";
    }
    
     //Check Title
    var title = document.getElementById("form_item_title_");
    if (title.value == 0) {
      alert("Please enter Title.");
      document.getElementById('error-title').innerHTML = " Please enter Title.";
      title.focus();
      return false;
    }else{
      document.getElementById('error-title').innerHTML = "";
    }


  }


function getSubCategories(obj){
  var div_subcate = document.getElementById('subcategories_container');
  var category = document.getElementById('form_categories_id_').value;

  if (category != 0)
  {
    var url = "index.php?module=IShopStore&type=ajax&func=list&ctrl=SubCategories&categories_id="+category+""+ genSession() ;
    div_subcate.innerHTML ="Loading...";
    new Ajax.Request(url, {
    method:'get',
    onSuccess: function(transport){
      var result = transport.responseText;
      div_subcate.innerHTML= result;
    }
    });
  }else{
    div_subcate.innerHTML ="<FONT size='2' COLOR='#FF0000'>Plese select Category....</FONT>";
    new Ajax.Request(url, {
    method:'get',
    onSuccess: function(transport){
    var result = transport.responseText;
    div_subcate.innerHTML= result;
  }
  });
  }
}

  function genSession(){
  return '&r=' + Math.random(999);
  }

  var item_count = 1;
  var max_item = 15;
  function addFileItem(){
    if (item_count < max_item){
      var div = document.getElementById('fileitemcontainer');
      var file = document.createElement('input');
      var br   = document.createElement('br');
      file.setAttribute('name' , 'images[]');
      file.setAttribute('type' , 'file');
      file.setAttribute('size' , '51');
      div.appendChild(file);
      div.appendChild(br);
      item_count++;
    }else{
      var addMore = document.getElementById('addFileMore');
      addMore.innerHTML = "";
    }
    return false;
  }

  function onSubmit(){
    var buttonContainner = document.getElementById('button');
    buttonContainner.align = 'center';
    buttonContainner.innerHTML = 'Uploading please wait...<br /><img src="modules/IShopStore/pnimages/loading.gif" />';
    form.submit();

    return false;
  }
</script>

<script>
  var valid_extensions = /(.jpg|.jpeg|.gif)$/i;

  function CheckExtension(fld)
  {

    if (valid_extensions.test(fld.value) || fld.value == ""){
       return true;
    }else{
      alert('โปรดใช้รูปนามสกุล .jpg , .jpeg หรือ .gif');
      fld.select();
      fld.focus();
      return false;
    }
  }
</script>


<!-- [$smarty.request.status] -->

<a href="<!--[pnmodurl modname='IShopStore' type='admin' func='list' ctrl='item']-->">
      <img src="modules/IShopStore/pnimages/back.png" align="absmiddle"/> กลับหน้ารายการสินค้า
 </a><BR>
<div align ='center'>
<!--[if $smarty.request.status eq 'success']-->
  <TABLE bgcolor="#99FF33" width="100%" align="center">
  <TR>
    <TD align="right" width="40%">
      <img align="absmiddle" src="modules/ishopstore/pnimages/success_icon.gif">&nbsp;&nbsp;
    </TD>
    <TD align="left" width="60%">
      <FONT SIZE="3" COLOR="#000000"><B>
        คุณได้ทำการ เพิ่ม/แก้ไข สินค้าเรียบร้อยแล้ว</B>
      </FONT><BR><A HREF="<!--[pnmodurl modname='IShopStore'  type='admin' func='list' ctrl='Item']-->"><FONT SIZE="2">กลับ</FONT></A>
    </TD>
  </TR>
  </TABLE>
<!--[/if]-->
</div>


<h2 align="center">เพิ่ม / แก้ไข สินค้า</h2>
<form class='form' id='form' enctype="multipart/form-data" action="<!--[pnmodurl modname='IShopStore' type='adminform' func='submit' ctrl='Item']-->" method="post" onsubmit="return validateForm(this)" onsubmit="return CheckExtension(this.elements['images'])"> 
  <input type="hidden" name="form[id]" value="<!--[$smarty.get.id]-->" />
  <input type="hidden" name="forward[modname]" value="IShopStore" />
  <input type="hidden" name="forward[type]" value="admin" />
  <input type="hidden" name="forward[func]" value="form" />
  <input type="hidden" name="forward[ctrl]" value="Item" />
  <input type="hidden" name="forward[id]" value="<!--[$_GET.id]-->" />

  <fieldset>
  <legend><FONT SIZE="2" COLOR="#0099FF"><B>รายละเอียด</B></FONT></legend>
  <table width="70%" border="0" class="table-label">
    <tr >
      <td class='td-label' >หมวดหมู่</td>
      <td class='td-data' >
        <TABLE>
          <TR>
            <TD><!--[selector_object_array_ex modname="IShopStore" 
                class="Categories" 
                field="id" 
                displayField="name"  
                name="form[categories_id]" 
                defaultText="กรุณาเลือก"
                selectedValue=$form.categories_id
                onChange="getSubCategories(this)"
                ]--><FONT SIZE="2" COLOR="#FF0000">&nbsp;*</FONT></TD>
            <TD><FONT SIZE="2" COLOR="#FF0000"><div id="error-category"></div></FONT></TD>
          </TR>
        </TABLE>
      
      </td>
    </tr>

    <tr>
      <td class='td-label' >ชื่อสินค้า</td>
      <td class='td-data' >
        <TABLE>
        <TR>
          <TD><input name="form[title]" 
                     id="form_item_title_" 
                     type="text" 
                     size="60" 
                     value="<!--[$form.title|pnvarprepfordisplay]-->" />
                     <FONT SIZE="2" COLOR="#FF0000">&nbsp;*</FONT></TD>
          <TD><FONT SIZE="2" COLOR="#FF0000"><div id="error-title"></div></FONT></TD>
        </TR>
        </TABLE>
      </td>
    </tr>
    <tr>
      <td class='td-label' >จำนวน</td>
      <td class='td-data' ><input name="form[amount]" 
                     id="form_item_amount_" 
                     type="text" 
                     size="5" 
                     value="<!--[$form.amount]-->" /></td>
    </tr>
    <tr>
      <td class='td-label' >รายละเอียด</td>
      <td class='td-data' >
        <TABLE>
        <TR>
          <TD>
            <textarea name='form[detail]' rows="4" cols="60"><!--[$form.detail]--></textarea></TD>
          <TD><FONT SIZE="2" COLOR="#FF0000"><div id="error-detail"></div></FONT></TD>
        </TR>
        </TABLE>
      </td>
    </tr>
    <tr>
      <td class='td-label' >ราคา</td>
      <td class='td-data' >
        <TABLE>
        <TR>
          <TD>
            <input name="form[price]" 
                     id="form_item_price_" 
                     type="text" 
                     size="10" 
                     value="<!--[$form.price]-->" /> บาท
     </TD>
          <TD><FONT SIZE="2" COLOR="#FF0000"><div id="error-detail"></div></FONT></TD>
        </TR>
        </TABLE>
      </td>
    </tr>
    <tr>
      <td class='td-label' >ลดราคา(option)</td>
      <td class='td-data' >
        <TABLE>
        <TR>
          <TD>
            <input name="form[sale_price]" 
                     id="form_item_sale_" 
                     type="text" 
                     size="10" 
                     value="<!--[$form.sale_price]-->" /> บาท</TD>
          <TD><FONT SIZE="2" COLOR="#FF0000"><div id="error-sale"></div></FONT></TD>
        </TR>
        </TABLE>
      </td>
    </tr>
  </table>
 
 <!-- <table width="30%" border="0">
    <tr>
      <td>ราคา</td>
      <td><span class="td-data">
        <input name="form[price]" 
                     id="form_item_price_" 
                     type="text" 
                     size="20" 
                     value="<!--[$form.price]-->" />
      บาท</span></td>
    </tr>
    <tr>
      <td>ลดราคา</td>
      <td><input name="form[sale_price]" 
                     id="form_item_sale_" 
                     type="text" 
                     size="20" 
                     value="<!--[$form.sale_price]-->" />
      บาท</td>
    </tr>
    <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table> -->
  </fieldset>
  <br>

  <fieldset>
  <legend><a href="#" onclick="Effect.toggle('icon_and_model', 'slide'); return false;"><img align="absmiddle" src="modules/IShopStore/pnimages/001_03.gif"  />รูป</a></legend>



  <div id="icon_and_model" >
  <table width="100%" border="0">
  <tr>
      <td>
        <table width="100%" border="0">
          <tr class='td-label'>
            <th width="5%" align="center">No.</td>
            <th width="50%" align="center">รูป</td>
            <th width="15%" align="center">รูปหลัก</td>
            <th width="15%" align="center">ลบรูป</td>
          </tr>
          <!--[foreach from=$extendResult.files item=img key=k]-->
          <tr bgcolor="<!--[cycle values="#FFFFFF,#E8EFF7"]-->">
            <td>
              <!--[$k+1]-->
            </td>
            <td>
              <IMG SRC="<!--[pngetbaseurl]--><!--[$img.thumbname]-->"  HEIGHT="100">
            </td>
            <td align="center">
              <!--[if $img.thumbname == $form.firstthumbname]--><input type="radio" name="form[firstimage]" value="<!--[$img.id]--> " checked />
              <!--[else]--><input type="radio" name="form[firstimage]" value="<!--[$img.id]-->"/>
              <!--[/if]--></td>
            <td align="center"><input type="checkbox" name="form[file_delete][]" value="<!--[$img.id]-->" /></td>
          </tr>
          <!--[/foreach]-->
        </table>
      </td>
    </tr>
    <tr>
      <td>&nbsp;</td>
    </tr>
    <tr>
    </tr>
  </table>
  </div>
  <fieldset>
  <legend>อัพโหลดรูป</legend>
    <TABLE>
    <tr>
      <td align="center" colspan="7"><div id="fileitemcontainer" >
        <input name="images[]" type="file" size="51"/><br />
        <input name="images[]" type="file" size="51"/><br />
        <input name="images[]" type="file" size="51"/><br />
        <input name="images[]" type="file" size="51"/><br />
        <input name="images[]" type="file" size="51"/><br />
      </div>
      <!--[if intval($user.level) gte intval($USER_VIP_LEVEL)]-->
      <div id="addFileMore">
      <a href="#" onclick="addFileItem();return false;">[ เพิ่มรูป]</a></div>
      <!--[/if]-->

      </td>
    </tr>
    </TABLE>
  </fieldset>
  </fieldset>
  <br>

  <fieldset>
    <div align="center" id='button'>
      <button id="button_submit" name="button_submit" value='Submit' type="submit" class="button" ><img align="absmiddle" src="modules/IShopStore/pnimages/submit.png" />Submit</button>&nbsp;&nbsp;
      <button id="button_cancel" name="button_cancel" value='Cancel' type="reset" onclick="window.address.href='#'" class="button" ><img align="absmiddle" src="modules/IShopStore/pnimages/cancel.png" />Reset</button>
    </div>
  </fieldset>
</form>
